import { Tank } from "../tank";
import { TankProps } from "../tankProps";
import { Image } from "leafer-ui";
export class AccelerateProp extends TankProps {
  constructor({ x, y }: { x: number; y: number }) {
    const recoveryProp = new Image({
      url: "/jiasu.png",
      width: 30,
      draggable: false,
      height: 30,
      x,
      y,
    });
    super({ x, y, targter: recoveryProp });
  }
  effect(tank: Tank): void {
    this.remove();
    const item = tank.stateProps.get("Accelerate");
    if (item) {
      clearTimeout(item);
    } else {
      tank.speed *= 1.5;
    }
    const t = setTimeout(() => {
      tank.speed = tank.speed / 1.5;
      tank.stateProps.delete("Accelerate");
    }, 20000);
    tank.stateProps.set("Accelerate", t);
  }
}
